package com.shop2cn.iapi.productcategory.testcase;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.model.Userinfo;
import com.ymttest.database.mongo.BuyerProductShop2cnWapper;
import com.ymttest.database.mongo.ProductBrandInfoWapper;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.shop2cn.iapi.productcategory.parameter.*;
import com.shop2cn.iapi.productcategory.service.*;

/**
 * FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_GetBrandByIdList {
	private static GetBrandByIdListBean GetBrandByIdListBean;
	private static GetBrandByIdListCall GetBrandByIdListCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据品牌Id列表获取品牌信息");
	}

	@Before
	public void caseUp() {
		GetBrandByIdListBean = new GetBrandByIdListBean();
		// 旧站点
		// GetBrandByIdListCall=new
		// GetBrandByIdListCall(EnvSetup.getSystemUrl("productcategory_api"));
		// 新站點
		GetBrandByIdListCall = new GetBrandByIdListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(GetBrandByIdListCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_GetBrandByIdList_001() {
		Logger.start(true, "根据品牌Id列表获取品牌信息成功");
		try {
			BuyerProductShop2cnWapper pbinfow = new BuyerProductShop2cnWapper();
			List<Integer> brandIdList = new ArrayList<Integer>();
			ArrayList<Map> list = pbinfow.getProductBrandInfos(5);
			for (Map map : list) {
				brandIdList.add(Integer.valueOf(map.get("BrandId").toString()));
			}
			// brandIdList.add(10731);
			GetBrandByIdListBean.setBrandIdList(brandIdList);
			GetBrandByIdListCall.setData(GetBrandByIdListBean);
			GetBrandByIdListCall.callService();
			Logger.verifyEquals("200", GetBrandByIdListCall.getString("Code"), "验证Code");
			JsonArray data = GetBrandByIdListCall.getData();
			for (JsonElement jsonElement : data) {
				BrandDto branddto = (BrandDto) FormatUtil.GSONToObject(jsonElement.getAsJsonObject().toString(), BrandDto.class);
				Map info = pbinfow.getProductBrandInfoById(branddto.getBrandId()).get(0);
				Logger.debug(info);
				Logger.verifyEquals(info.get("Alias"), branddto.getAlias(), "验证Alias");
				Logger.verifyEquals(info.get("BrandBannerUrl"), branddto.getBrandBannerUrl(), "验证BrandBannerUrl");
				Logger.verifyEquals(info.get("BrandBizSector"), branddto.getBrandBizSector(), "验证BrandBizSector");
				Logger.verifyEquals(info.get("BrandDescription"), branddto.getBrandDescription(), "验证BrandDescription");
				Logger.verifyEquals(info.get("BrandDescriptionEn"), branddto.getBrandDescriptionEn(), "验证BrandDescriptionEn");
				Logger.verifyEquals(info.get("BrandEnName"), branddto.getBrandEnName(), "验证BrandEnName");
				Logger.verifyEquals(info.get("BrandLogoUrl"), branddto.getBrandLogoUrl(), "验证BrandLogoUrl");
				Logger.verifyEquals(info.get("BrandName"), branddto.getBrandName(), "验证BrandName");
				// Logger.verifyEquals(info.get("BrandEnName").toString().substring(0,
				// 1).toUpperCase(), branddto.getKeyWord(),
				// "验证KeyWord");//keyword?BrandEnName首字母大写？有些不是,待确认
				// Logger.verifyEquals(0, branddto.getLevel(), "验证Level");
				Logger.verifyEquals(info.get("ProductCount"), branddto.getProductCount(), "验证ProductCount");
				if (info.get("CountryId") != null) {
					Logger.verifyEquals(info.get("CountryId"), branddto.getCountryId(), "验证CountryId");
				} else {
					Logger.debug(branddto.getBrandName() + "not found CountryId");
				}
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_GetBrandByIdList_002() {
		Logger.start(true, "批量根据品牌Id列表获取品牌信息成功");
		try {
			BuyerProductShop2cnWapper pbinfow = new BuyerProductShop2cnWapper();

			List<Integer> brandIdList = new ArrayList<Integer>();
			ArrayList<Map> list = pbinfow.getProductBrandInfos(100);
			int count = 0;
			for (Map map : list) {
				brandIdList.add(Double.valueOf(map.get("BrandId").toString()).intValue());
				count++;
				if (count >= 5) {
					GetBrandByIdListBean.setBrandIdList(brandIdList);
					GetBrandByIdListCall.setData(GetBrandByIdListBean);
					GetBrandByIdListCall.callService();
					Logger.verifyEquals("200", GetBrandByIdListCall.getString("Code"), "验证Code");
					JsonArray data = GetBrandByIdListCall.getData();
					for (JsonElement jsonElement : data) {
						BrandDto branddto = (BrandDto) FormatUtil.GSONToObject(jsonElement.getAsJsonObject().toString(), BrandDto.class);
						Map info = pbinfow.getProductBrandInfoById(branddto.getBrandId()).get(0);
						Logger.debug(info);
						Logger.verifyEquals(info.get("Alias"), branddto.getAlias(), "验证Alias");
						Logger.verifyEquals(info.get("BrandBannerUrl"), branddto.getBrandBannerUrl(), "验证BrandBannerUrl");
						Logger.verifyEquals(info.get("BrandBizSector"), branddto.getBrandBizSector(), "验证BrandBizSector");
						Logger.verifyEquals(info.get("BrandDescription"), branddto.getBrandDescription(), "验证BrandDescription");
						Logger.verifyEquals(info.get("BrandDescriptionEn"), branddto.getBrandDescriptionEn(), "验证BrandDescriptionEn");
						Logger.verifyEquals(info.get("BrandEnName"), branddto.getBrandEnName(), "验证BrandEnName");
						Logger.verifyEquals(info.get("BrandLogoUrl"), branddto.getBrandLogoUrl(), "验证BrandLogoUrl");
						Logger.verifyEquals(info.get("BrandName"), branddto.getBrandName(), "验证BrandName");
						// Logger.verifyEquals(info.get("BrandEnName").toString().substring(0,
						// 1).toUpperCase(), branddto.getKeyWord(),
						// "验证KeyWord");//keyword?BrandEnName首字母大写？有些不是,待确认
						// Logger.verifyEquals(0, branddto.getLevel(),
						// "验证Level");
						Logger.verifyEquals(info.get("ProductCount"), branddto.getProductCount(), "验证ProductCount");
					}
					brandIdList = new ArrayList<Integer>();
					GetBrandByIdListCall = new GetBrandByIdListCall();
					count = 0;
				}
			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}